/*
 * @描述: 账户数据请求
 * @版权所有: 广东国星科技有限公司
 * @商业授权: www.mscodecloud.com
 */
import { updateSysUserDetail, updatePassword, updateSysUserInfo } from '@/services/api';

export default {
  namespace: 'account',

  state: {

  },

  effects: {
    *update({ payload }, { call, put }) {
      const response = yield call(updateSysUserDetail, payload);
      yield put({
        type: 'save',
        payload: response
      });
      if (!response.message) return;
      return response;
    },
    *updatePassword({ payload }, { call, put }) {
      const response = yield call(updatePassword, payload);
      yield put({
        type: 'save',
        payload: response
      });
      if (!response.message) return;
      return response;
    },
    *updateSysUserInfo({ payload }, { call, put }) {
      const response = yield call(updateSysUserInfo, payload);
      yield put({
        type: 'save',
        payload: response
      });
      if (!response.message) return;
      return response;
    }
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload.data
      };
    }
  }
};